﻿<phone:PhoneApplicationPage
    x:Class="WP8.Views.EventToReactive"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="clr-namespace:Sample.ViewModels;assembly=Sample.ViewModels"
    xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Interactivity"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:r="clr-namespace:Codeplex.Reactive.Interactivity;assembly=ReactiveProperty.WP8"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.DataContext>
        <vm:EventToReactiveViewModel />
    </phone:PhoneApplicationPage.DataContext>
    <!-- recommend App.xaml.cs global resource -->
    <phone:PhoneApplicationPage.Resources>
        <vm:Converters x:Key="Converters" />
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="EventToReactive" Style="{StaticResource PhoneTextNormalStyle}"/>
        </StackPanel>

        <Grid Grid.Row="1">
            <!-- Use Blend SDK's Interaction Trigger -->
            <!-- Event binding to ReactiveProperty -->
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseMove">
                    <!-- ConvertBack function is Func<object, object>-->
                    <r:EventToReactive ReactiveProperty="{Binding MouseMove}" 
                                   Converter="{Binding MouseEventToPoint, Source={StaticResource Converters}}" />
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeftButtonUp">
                    <!-- direct event bind -->
                    <r:EventToReactive ReactiveProperty="{Binding MouseUp}" />
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseEnter">
                    <!-- IgnoreEventArgs = true send Unit -->
                    <r:EventToReactive ReactiveProperty="{Binding MouseEnter}" IgnoreEventArgs="true" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <TextBlock Text="{Binding CurrentPoint.Value}" />
            <TextBlock Text="{Binding Entered.Value}" Margin="0,100,0,0" />
        </Grid>
    </Grid>


</phone:PhoneApplicationPage>